{if !empty($danmulisttop)}

{if $config['isdanmu']==1}
        <div class="top_pop">
            <ul id="top_pop">
                {loop $danmulisttop $item}
                    <li>
                        <h3 class="pop">
                            <img src="{$item['img']}">
                            <font>{$item['nickname']}</font>
                            <span>{$item['info']}</span>
                        </h3>
                    </li>
                    <li></li>
                {/loop}
            </ul>
        </div>
{/if}

<script>

var html_data = [

                {loop $danmulisttop $item}
{ 
	nickname : '{$item['nickname']}{$item['info']}',
	head_url : "{$item['img']}"
},			

                {/loop}
]

{if $config['isdanmu']==1}
	var top_arr = [50,95,140,185];
{else}
	var top_arr = [5,50,95,140];
{/if}

var top_num = 0;
function makeHtml(num){
	//var speed = ['danmu-fast', 'danmu-normal', 'danmu-slow'];
	var speed = ['danmu-slow', 'danmu-slow', 'danmu-slow'];
	var get_speed = Math.floor(Math.random() * speed.length);
	var get_top = Math.floor(Math.random() * 30);
	var tmpl =	'<div class="danmu ' 
				+ speed[get_speed] 
				+ '" style="top:' 
				+ top_arr[top_num] + 'px">' 
				+ '<img src="' 
				+ html_data[num].head_url 
				+ '" style="width:25px;"> '
				+ html_data[num].nickname 
				+ '</div>';

	$("#get_danmu").append(tmpl);
}


var danmu_num = 0;
function danmu_start(){
	var _length = html_data.length - 1;
	// if (top_num >= (top_arr.length - 1)) {
	// 	top_num = 0;
	// } else {
	// 	top_num += 1;
	// };

	top_numa = Math.floor(Math.random() * top_arr.length);
	if (top_num==top_numa){
		top_numa = Math.floor(Math.random() * top_arr.length);
		if (top_num==top_numa){
			top_numa = Math.floor(Math.random() * top_arr.length);
			if (top_num==top_numa){
				top_numa = Math.floor(Math.random() * top_arr.length);
				if (top_num==top_numa){
					top_numa = Math.floor(Math.random() * top_arr.length);
				}
			}
		}
	} 
	top_num=top_numa;

	makeHtml(danmu_num);

	if (danmu_num >= _length && danmu_num>10) {
		danmu_num = 0;
	} else {
		danmu_num += 1;
	};

	$(".danmu").each(function(){
	    var s = $(this).offset().left;
	    //console.log(s);
	    if (s <= -420) {
	    	$(this).remove();
	    	//console.log("删除")
	    }
	});

}
var interval = setInterval(danmu_start, 1000);


var n=0,
	timer=null,
	time=null;

timer=setInterval(function(){
	n++
	if(n>=$('#top_pop li').length){
		n=0;
	}
	$('#top_pop').css('top',`-${30*n}px`);
},2000)

//弹幕开关
// $("#dm_button").click(function(){
// 	if ($(this).hasClass('dm_off')) {
// 		$(this).removeClass('dm_off');
// 		$("#get_danmu").show();
// 		interval = setInterval(danmu_start, 1000);
// 	} else {
// 		$(this).addClass('dm_off');
// 		$("#get_danmu").hide();
// 		$(".danmu").remove();
// 		clearInterval(interval);
// 	};
// })

</script>
{/if}